package com.cw.jeeyt.service.impl.system;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cw.jeeyt.service.bo.system.SystemProjectInfoBo;
import com.cw.jeeyt.core.util.SessionUtil;
import com.cw.jeeyt.dao.intf.system.SystemProjectInfoDao;
import com.cw.jeeyt.dao.model.system.SystemProjectInfoDo;
import com.cw.jeeyt.service.converter.system.SystemProjectInfoConverter;
import com.cw.jeeyt.service.intf.system.SystemProjectInfoService;
import com.cw.lang.mybatis.dto.PageInfo;
import com.cw.lang.common.utils.SequenceTool;

/**
 * 项目信息业务实现类
 *
 * @author chenw
* @version 1.0.0
 */
@Service
public class SystemProjectInfoServiceImpl implements SystemProjectInfoService {

    private static final Logger logger = LoggerFactory.getLogger(SystemProjectInfoServiceImpl.class);
    @Autowired
    private SystemProjectInfoDao systemProjectInfoDao;//项目信息数据库操作接口

    /**
     * 新增SystemProjectInfo
     *
     * @param systemProjectInfoBo
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertSystemProjectInfo(SystemProjectInfoBo systemProjectInfoBo) throws Exception {

        if (systemProjectInfoBo == null) {
            logger.error("项目信息为空");
            return;
        }
        SystemProjectInfoDo systemProjectInfo = SystemProjectInfoConverter.bo2Do(systemProjectInfoBo);
        systemProjectInfo.setId(SequenceTool.nextId());
        systemProjectInfo.setCreateBy(SessionUtil.getSessionUserId());
        systemProjectInfo.setCreateDate(new Date());
        systemProjectInfo.setUpdateBy(SessionUtil.getSessionUserId());
        systemProjectInfo.setUpdateDate(new Date());
        systemProjectInfoDao.insertSystemProjectInfo(systemProjectInfo);
    }

    /**
     * 更新SystemProjectInfo信息
     *
     * @param systemProjectInfoBo
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateSystemProjectInfo(SystemProjectInfoBo systemProjectInfoBo) throws Exception {

        if (systemProjectInfoBo == null) {
            logger.error("项目信息为空");
            return;
        }
        SystemProjectInfoDo systemProjectInfo = SystemProjectInfoConverter.bo2Do(systemProjectInfoBo);
        systemProjectInfo.setUpdateBy(SessionUtil.getSessionUserId());
        systemProjectInfo.setUpdateDate(new Date());
        systemProjectInfoDao.updateSystemProjectInfo(systemProjectInfo);
    }

    /**
     * 删除SystemProjectInfo
     *
     * @param systemProjectInfoBo
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteSystemProjectInfo(SystemProjectInfoBo systemProjectInfoBo) throws Exception {
        if (systemProjectInfoBo == null) {
            logger.error("项目信息为空");
            return;
        }
        systemProjectInfoDao.deleteSystemProjectInfo(SystemProjectInfoConverter.bo2Do(systemProjectInfoBo));

    }

    /**
     * 查询所有项目信息
     *
     * @return 项目信息集合
     */
    @Override
    public List<SystemProjectInfoBo> querySystemProjectInfoList() throws Exception {
        return SystemProjectInfoConverter.doList2BoList(systemProjectInfoDao.querySystemProjectInfoList());
    }

    /**
     * 分页查询SystemProjectInfo
     *
     * @param systemProjectInfoBo
     * @param startNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<SystemProjectInfoBo> queryByPage(SystemProjectInfoBo systemProjectInfoBo, Integer startNum,
        Integer pageSize) throws Exception {
        PageInfo<SystemProjectInfoDo> pageInfo = systemProjectInfoDao.queryByPage(
            SystemProjectInfoConverter.bo2Do(systemProjectInfoBo), startNum, pageSize);
        return new PageInfo<>(pageInfo, SystemProjectInfoConverter.doList2BoList(pageInfo.getList()));
    }

    /**
     * 根据主键查询SystemProjectInfo信息
     *
     * @param id
     * @return
     */
    @Override
    public SystemProjectInfoBo getSystemProjectInfoById(String id) throws Exception {
        return SystemProjectInfoConverter.do2Bo(systemProjectInfoDao.getSystemProjectInfoById(id));
    }
}
